package org.jeecgframework.web.system.pojo.base;

import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.jeecgframework.core.util.ApplicationContextUtil;
import org.jeecgframework.core.util.DateUtils;
import org.jeecgframework.core.util.StringUtil;
import org.jeecgframework.web.system.service.SystemService;
import org.jeecgframework.web.util.ExcelUtil;
import org.jeecgframework.web.util.StaticValue;

/**
 * @author xiul
 * 2016-6-6 下午5:08:15
 * Description 
 */
public class ZyUpInspectionRecordThread extends Thread{
	
	private static SystemService systemService = ApplicationContextUtil.getBean("systemService");
	
	private int beginR;
	private int endR;
	private List<Map<String, Object>> mapList;
	
	public ZyUpInspectionRecordThread(){}

	/**
	 * @param beginRow 开始行数
	 * @param endRow 结束行数
	 * @param mapList sheet页
	 */
	public ZyUpInspectionRecordThread(int beginRow, int endRow, List<Map<String, Object>> mapList){
		this.beginR = beginRow;
		this.endR = endRow;
		this.mapList = mapList;
	}
	
	public void run(){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
		Date begin = new Date();
		System.out.println("线程:"+Thread.currentThread().getId()+"\t,开始解析："+ beginR +"\t至\t"+ endR);
		List<ZyInspectionRecordEntity> result = new ArrayList<ZyInspectionRecordEntity>();
		for(int r = beginR; r <= endR; r++) {
			Map<String,Object> row = mapList.get(r);
			if(null != row){
				ZyInspectionRecordEntity zyInspectionRecord = new ZyInspectionRecordEntity();
				zyInspectionRecord.setSpareSn(row.get("0").toString());
				zyInspectionRecord.setPlanId(row.get("1").toString());
				zyInspectionRecord.setActualDate(DateUtils.str2Date(row.get("2").toString(), sdf));
				zyInspectionRecord.setCompany(row.get("3").toString()); // xssfCell.getRichStringCellValue().getString();  
				zyInspectionRecord.setEngineer(row.get("4").toString());
				zyInspectionRecord.setHouse(row.get("5").toString());
				zyInspectionRecord.setYtRmTemperature(row.get("6").toString());
				try {
					BigDecimal decimal = new BigDecimal(Double.valueOf(row.get("7").toString()));
					zyInspectionRecord.setYtRmHumidity(decimal.setScale(3, BigDecimal.ROUND_HALF_UP).toString());
				} catch (Exception e) {}
				zyInspectionRecord.setLqCoolantLiquidH(row.get("8").toString()); 
				zyInspectionRecord.setLqScoreCoolant(row.get("9").toString());
//				zyInspectionRecord.setLqVentSpeed(row.get("10").toString());
				try {
					BigDecimal decimal = new BigDecimal(Double.valueOf(row.get("10").toString()));
					zyInspectionRecord.setLqVentSpeed(decimal.setScale(3, BigDecimal.ROUND_HALF_UP).toString());
				} catch (Exception e) {}
				zyInspectionRecord.setQjDustFilterClMp(row.get("11").toString());
//				zyInspectionRecord.setXlZeroVoltage(row.get("12").toString());
				try {
					BigDecimal decimal = new BigDecimal(Double.valueOf(row.get("12").toString()));
					zyInspectionRecord.setXlZeroVoltage(decimal.setScale(3, BigDecimal.ROUND_HALF_UP).toString());
				} catch (Exception e) {}
				zyInspectionRecord.setXdRunTime(row.get("13").toString());
				zyInspectionRecord.setXdRunCount(row.get("14").toString());
				zyInspectionRecord.setGxLightPath(row.get("15").toString());
				zyInspectionRecord.setYxLightC(row.get("16").toString());
				zyInspectionRecord.setTotalRunTime(row.get("17").toString());
				zyInspectionRecord.setAfterScore(row.get("18").toString());
				zyInspectionRecord.setEngItemId(row.get("19").toString());
				zyInspectionRecord.setTiIcpItemId(row.get("20").toString());
				zyInspectionRecord.setLpsItemId(row.get("21").toString());
				zyInspectionRecord.setEnigmaItemId(row.get("22").toString());
				zyInspectionRecord.setControlerItemId(row.get("23").toString());
				zyInspectionRecord.setSmpsItemId(row.get("24").toString());
				zyInspectionRecord.setServerBrand(row.get("25").toString());
				zyInspectionRecord.setServerModel(row.get("26").toString());
				zyInspectionRecord.setComprehensiveEvaluation(row.get("27").toString());
				result.add(zyInspectionRecord);
			}
		}
		systemService.batchSave(result);
		Date end = new Date();
		SimpleDateFormat sf = new SimpleDateFormat("HH:mm:ss");
		System.err.println("线程:"+this.getThreadGroup().getName()+"\n结束解析："+ beginR +"\n至\n"+ endR + "\n本线程 用时："+ sf.format(new Date(end.getTime() - begin.getTime())));
	}

//	/**
//	 * @author zhangyunlong
//	 * 2016-6-17 下午4:26:03
//	 * Description 
//	 */
//    private static String getCellStringValue(XSSFCell xssfCell){  
//    	String value="";
//    	if(null == xssfCell){
//    		return value;
//    	}
//    	String cellVal = xssfCell);  
//    	if(isInteger(cellVal)){
//    		value = String.valueOf(dd);
//    	}else{
//    		value = String.valueOf(xssfCell.getNumericCellValue());  
//    	}
//        return value;  
//    }
//    
//    /**
//     * @author zhangyunlong
//     * 判断字符串是否为整数
//     */
//    private static boolean isInteger(String str){
//    	int decimal = 0; 
//    	if(null != str && str.indexOf(".") > 0){
//    		decimal = Integer.valueOf(str.substring(str.indexOf(".")+1));
//    		if(decimal > 0){
//    			return false;
//    		}
//    	}
//    	return true;
//    }

	public int getBeginR() {
		return beginR;
	}
	public void setBeginR(int beginR) {
		this.beginR = beginR;
	}

	public int getEndR() {
		return endR;
	}
	public void setEndR(int endR) {
		this.endR = endR;
	}

	public List<Map<String, Object>> getMapList() {
		return mapList;
	}
	public void setMapList(List<Map<String, Object>> mapList) {
		this.mapList = mapList;
	}
	
	
	
}
